package com.qzw.security.api.model;

import com.qzw.common.api.base.BaseModel;
import io.swagger.annotations.ApiModelProperty;

/**
 * @author ：quziwei
 * @date ：Created in 2020/6/2 11:58 上午
 * @description：
 */
public class Resource extends BaseModel<Integer> {

    public static final String SEPARATOR = ":";

    @ApiModelProperty(readOnly = true)
    private String resource;
    @ApiModelProperty(value = "请求方法", allowableValues = "GET,POST,DELETE,PUT", allowEmptyValue = true)
    private String method = "ALL";
    @ApiModelProperty(required = true)
    private String path;

    public String getMethod() {
        return method;
    }

    public void setMethod(String method) {
        this.method = method.toUpperCase();
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public String getResource() {
        return getMethod().toUpperCase() + SEPARATOR + getPath();
    }

    public void setResource(String resource) {
        String[] split = resource.split(SEPARATOR);
        this.method = split[0].toUpperCase();
        this.path = split[1];
        this.resource = resource;
    }
}
